package com.wn.icloud.common.msg;


/**
 * Created by Rainer on 2017/6/11.
 */
public class ObjectRestResponse<T> extends BaseResponse {

    T data;
    boolean rel;

    public boolean isRel() {
        return rel;
    }

    public void setRel(boolean rel) {
        this.rel = rel;
    }


    public ObjectRestResponse rel(boolean rel) {
        this.setRel(rel);
        return this;
    }


    public ObjectRestResponse data(T data) {
        this.setData(data);
        return this;
    }
    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static ObjectRestResponse success() {
        ObjectRestResponse result = new ObjectRestResponse();
        result.setRel(true);
        result.setResultCode(ObjectRestCode.SUCCESS);
        return result;
    }

    public static ObjectRestResponse success(Object data) {
        ObjectRestResponse result = new ObjectRestResponse();
        result.setRel(true);
        result.setResultCode(ObjectRestCode.SUCCESS);
        result.setData(data);
        return result;
    }

    public static ObjectRestResponse failure(ObjectRestCode resultCode) {
        ObjectRestResponse result = new ObjectRestResponse();
        result.setRel(false);
        result.setResultCode(resultCode);
        return result;
    }

    public static ObjectRestResponse failure(ObjectRestCode resultCode, Object data) {
        ObjectRestResponse result = new ObjectRestResponse();
        result.setRel(false);
        result.setResultCode(resultCode);
        result.setData(data);
        return result;
    }

    public void setResultCode(ObjectRestCode code) {
        super.setStatus(code.code());
        super.setMessage(code.message());
    }


    public ObjectRestResponse(int status, String message, T data, boolean rel) {
        super(status, message);
        this.data = data;
        this.rel = rel;
    }

    public ObjectRestResponse(int status, String message) {
        super(status, message);
    }

    public ObjectRestResponse() {
    }
}
